﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models {
    import reprise.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.vo.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;

    public class ShopModel extends Actor {

        private var _shopItems:Array;
        private var _insideDestinations:Array;
        private var _outsideDestinations:Array;
        private var _insideAndOutsideDestinations:Array;

        public function ShopModel(){
            this._insideDestinations = [ShopItemVO.DESTINATION_ROOM, ShopItemVO.DESTINATION_FLOOR, ShopItemVO.DESTINATION_CEILING, ShopItemVO.DESTINATION_WALL];
            this._outsideDestinations = [ShopItemVO.DESTINATION_FACADE, ShopItemVO.DESTINATION_GARDEN, ShopItemVO.DESTINATION_ROOF, ShopItemVO.DESTINATION_ELEVATOR_ROOF];
            this._insideAndOutsideDestinations = [ShopItemVO.DESTINATION_ROOM, ShopItemVO.DESTINATION_GARDEN];
            super();
            this._shopItems = [];
        }
        public function addShopItem(_arg1:ShopItemVO):void{
            this._shopItems.push(_arg1);
        }
        public function existsShopItemWithType(_arg1:String):Boolean{
            return (!((this.getShopItemByType(_arg1) == null)));
        }
        public function getShopItemByType(_arg1:String):ShopItemVO{
            var _local2:ShopItemVO;
            var _local3:int = this._shopItems.length;
            while (_local3--) {
                _local2 = this._shopItems[_local3];
                if (_local2.type == _arg1){
                    return (_local2);
                };
            };
            return (null);
        }
        public function getItemsByCategory(_arg1:String):Array{
            var _local3:ShopItemVO;
            var _local2:Array = [];
            var _local4:int = this._shopItems.length;
            while (_local4--) {
                _local3 = this._shopItems[_local4];
                if (_local3.category == _arg1){
                    _local2.push(_local3.type);
                };
            };
            return (_local2);
        }
        public function increaseNumberOfItem(_arg1:String, _arg2:String):void{
            var _local3:ShopItemVO = this.getShopItemByType(_arg1);
            if (_local3){
                _local3.numberOfItems.push(_arg2);
                dispatch(new ShopEvent(ShopEvent.ON_ITEM_COUNT_CHANGED_BY_PUTTING_BACK, _local3));
            };
        }
        public function updateIDsOfType(_arg1:String, _arg2:Array):void{
            var _local3:ShopItemVO = this.getShopItemByType(_arg1);
            if (_local3.count == _arg2.length){
                return;
            };
            _local3.numberOfItems = _arg2;
            dispatch(new ShopEvent(ShopEvent.ON_ITEM_COUNT_CHANGED, _local3));
        }
        public function get shopItems():Array{
            return (this._shopItems);
        }
        public function getLocationByDestination(_arg1:String):String{
            _arg1 = StringUtil.trim(_arg1);
            if (Arrays.contains(this._insideAndOutsideDestinations, _arg1)){
                return (ShopItemVO.LOCATION_INSIDE_AND_OUTSIDE);
            };
            if (Arrays.contains(this._outsideDestinations, _arg1)){
                return (ShopItemVO.LOCATION_OUTSIDE);
            };
            if (Arrays.contains(this._insideDestinations, _arg1)){
                return (ShopItemVO.LOCATION_INSIDE);
            };
            return (null);
        }
        public function integrateStoredItems(_arg1:Object):void{
            var _local2:Object;
            for each (_local2 in _arg1) {
                this.increaseNumberOfItem(_local2.element_type, _local2.id);
            };
        }

    }
}//package net.wooga.pets.models 
